home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Medal Software 3
/
Gold Medal Software - Volume 3 (Gold Medal) (1994).iso
/
prog
/
pbc23c.arj
/
SHOWBMP.BAS
< prev
next >
Wrap
BASIC Source File
|
1994-03-13
|
4KB
|
100 lines
' +----------------------------------------------------------------------+
' | |
' | PBClone Copyright (c) 1990-1994 Thomas G. Hanlin III |
' | |
' +----------------------------------------------------------------------+
DECLARE FUNCTION AscM% (St$, BYVAL Posn%)
DECLARE SUB DFRead (BYVAL FileHandle%, BYVAL DSeg%, BYVAL DOfs%, BYVAL Bytes%, BytesRead%, ErrCode%)
DECLARE SUB FClose1 (BYVAL FileHandle%)
DECLARE SUB FOpen1 (FileName$, BYVAL ReadWrite%, BYVAL Sharing%, FileHandle%, ErrCode%)
DECLARE SUB FSetLoc (BYVAL FileHandle%, Posn&)
DECLARE FUNCTION FSize2& (BYVAL FileHandle%)
DECLARE SUB SFRead (BYVAL FileHandle%, St$, BytesRead%, ErrCode%)
DECLARE SUB PalBlock0 (BYVAL DSeg%, BYVAL DOfs%, BYVAL Colors%)
SUB ShowBMP (File$, OrigX%, OrigY%, ErrCode%)
ErrCode% = 0
FOpen1 File$, 0, 2, Handle%, ErrCode% ' open for read, deny write
IF ErrCode% = 0 THEN
Header$ = SPACE$(54)
SFRead Handle%, Header$, BytesRead%, ErrCode%
IF ErrCode% = 0 THEN
PWide& = CVL(MID$(Header$, 19, 4))
PHigh& = CVL(MID$(Header$, 23, 4))
BitPlanes% = CVI(MID$(Header$, 27, 2))
ColorBits% = CVI(MID$(Header$, 29, 2))
IF LEFT$(Header$, 2) <> "BM" THEN
ErrCode% = -1 ' invalid BMP
ELSEIF NOT (BitPlanes% = 1 AND ColorBits% = 8) THEN
ErrCode% = -2 ' color format not supported
ELSEIF CVL(MID$(Header$, 31, 4)) <> 0& THEN
ErrCode% = -3 ' compression not supported
ELSEIF CVL(MID$(Header$, 3, 4)) <> FSize2&(Handle%) THEN
ErrCode% = -4 ' incorrect file size
ELSEIF PWide& < 1& OR PHigh& < 1& THEN
ErrCode% = -5 ' ludicrous image size
ELSEIF PWide& > 320& OR PHigh& > 200& THEN
IF OrigX% >= 0 AND OrigY% >= 0 THEN
ErrCode% = -5 ' ludicrous image size
END IF
END IF
IF ErrCode% = 0 THEN
PicWidth% = PWide&
PicHeight% = PHigh&
IF OrigX% < 0 OR OrigY% < 0 THEN
OX% = 0
OY% = 0
IF PicWidth% > 320 OR PicHeight% > 200 THEN
WideRatio! = PicWidth% / 320!
HighRatio! = PicHeight% / 200!
IF WideRatio! > HighRatio! THEN
MaxX! = PicWidth% - 1
MaxY! = 200! * WideRatio!
ELSE
MaxX! = 320! * HighRatio!
MaxY! = PicHeight% - 1
END IF
WINDOW SCREEN (0, 0)-(MaxX!, MaxY!)
END IF
ELSEIF OrigX% + PicWidth% > 320 OR OrigY% + PicHeight% > 200 THEN
ErrCode% = -6 ' invalid (X,Y) origin specified
ELSE
OX% = OrigX%
OY% = OrigY%
END IF
END IF
END IF
'----- set the palette -----
IF ErrCode% = 0 THEN
DIM Pal&(0 TO 255)
DSeg% = VARSEG(Pal&(0))
DOfs% = VARPTR(Pal&(0))
Bytes% = 1024 ' 256 * 4 is size of palette block
DFRead Handle%, DSeg%, DOfs%, Bytes%, BytesRead%, ErrCode%
IF ErrCode% = 0 THEN
PalBlock0 DSeg%, DOfs%, 256
END IF
END IF
'----- draw the picture -----
IF ErrCode% = 0 THEN
FSetLoc Handle%, CVL(MID$(Header$, 11, 4)) + 1&
Bytes% = ((PicWidth% + 3) \ 4) * 4
st$ = SPACE$(Bytes%)
FOR y% = 0 TO PicHeight% - 1
SFRead Handle%, st$, BytesRead%, ErrCode%
IF ErrCode% THEN EXIT FOR
CurrY% = (PicHeight% - y%) + OY%
FOR x% = 0 TO PicWidth% - 1
PSET (x% + OX%, CurrY%), AscM(st$, x% + 1)
NEXT
NEXT
END IF
FClose1 Handle%
END IF
END SUB